package initialize

import (
	"context"

	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/system"
	"github.com/flipped-aurora/gin-vue-admin/server/plugin/plugin-tool/utils"
)

// Api 注册API到数据库
func Api(ctx context.Context) {
	// 智能表单API权限配置
	entities := []system.SysApi{
		// 表单管理相关API
		{
			Path:        "/intelligent-form/form/create",
			Description: "创建表单",
			ApiGroup:    "智能表单",
			Method:      "POST",
		},
		{
			Path:        "/intelligent-form/form/update",
			Description: "更新表单",
			ApiGroup:    "智能表单",
			Method:      "PUT",
		},
		{
			Path:        "/intelligent-form/form/delete",
			Description: "删除表单",
			ApiGroup:    "智能表单",
			Method:      "DELETE",
		},
		{
			Path:        "/intelligent-form/form/detail",
			Description: "获取表单详情",
			ApiGroup:    "智能表单",
			Method:      "GET",
		},
		{
			Path:        "/intelligent-form/form/list",
			Description: "获取表单列表",
			ApiGroup:    "智能表单",
			Method:      "GET",
		},
		{
			Path:        "/intelligent-form/form/publish",
			Description: "发布表单",
			ApiGroup:    "智能表单",
			Method:      "POST",
		},
		{
			Path:        "/intelligent-form/form/close",
			Description: "关闭表单",
			ApiGroup:    "智能表单",
			Method:      "POST",
		},
		// 提交记录管理相关API
		{
			Path:        "/intelligent-form/submission/list",
			Description: "获取提交记录列表",
			ApiGroup:    "智能表单",
			Method:      "GET",
		},
		{
			Path:        "/intelligent-form/submission/detail",
			Description: "获取提交记录详情",
			ApiGroup:    "智能表单",
			Method:      "GET",
		},
		{
			Path:        "/intelligent-form/submission/delete",
			Description: "删除提交记录",
			ApiGroup:    "智能表单",
			Method:      "DELETE",
		},
		// 提交数据导出API
		{
			Path:        "/intelligent-form/submission/export",
			Description: "导出提交数据",
			ApiGroup:    "智能表单",
			Method:      "GET",
		},
		// 公开接口（无需认证）
		{
			Path:        "/intelligent-form/public/form",
			Description: "获取公开表单",
			ApiGroup:    "智能表单公开接口",
			Method:      "GET",
		},
		{
			Path:        "/intelligent-form/public/submit",
			Description: "提交表单数据",
			ApiGroup:    "智能表单公开接口",
			Method:      "POST",
		},
		// 生成表单接口（无需认证）
		{
			Path:        "/intelligent-form/generated/form",
			Description: "获取生成的表单",
			ApiGroup:    "智能表单公开接口",
			Method:      "GET",
		},
		{
			Path:        "/intelligent-form/generated/submit",
			Description: "提交生成的表单",
			ApiGroup:    "智能表单公开接口",
			Method:      "POST",
		},
	}

	// 添加日志以便调试
	global.GVA_LOG.Info("正在注册智能表单插件API权限...")
	utils.RegisterApis(entities...)
	global.GVA_LOG.Info("智能表单插件API权限注册完成")
}
